//
//  WallpaperCell.swift
//  HLDesktop
//
//  Created by 子凡 on 2023/9/16.
//

import UIKit

class WallpaperCell: UICollectionViewCell {
    lazy var mImage: UIImageView = {
        let mImage = UIImageView()
        mImage.contentMode = .scaleAspectFill
        mImage.clipsToBounds = true
        return mImage
    }()
    
    lazy var authorLabel: UILabel = {
        let label = UILabel()
        label.font = .systemFont(ofSize: 12)
        label.textColor = .secondaryLabel
        label.textAlignment = .right
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        self.addSubview(self.mImage)
        self.mImage.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
        self.mImage.setShadow(shadowColor: prjTitleColor, offset: CGSize(width: 1, height: 1), opacity: 0.25, radius: 10)
        self.mImage.addSubview(self.authorLabel)
        self.authorLabel.frame = CGRect(x: 5, y: self.bounds.height-30, width: self.bounds.width-10, height: 30)
    }
    
    func updateCellImg(imgName:String,And author:String?){
        self.mImage.setImageWithStr(imgurl: imgName)
        self.authorLabel.font = .systemFont(ofSize: 12)
        if author != nil && author!.count>0{
            self.authorLabel.text = String(format: "--by %@", author!)
        }else{
            self.authorLabel.text = ""
        }
    }
    
    func updateGifCell(imgName:String){
//        self.mImage.image = UIImage(named: imgName)//使用SDWebImage后在Collection中显示不会自动清除，但仍会比较卡,故直接UIImage(named:)自动显示静态图片即可
        self.mImage.setImageWithStr(imgurl: imgName)
        self.authorLabel.font = .systemFont(ofSize: 10)
        self.authorLabel.text = "✺LIVE"
    }
}
